package com.niodata.dp.task.entity.v2;

import com.niodata.dp.collection.StringList;
import com.niodata.dp.core.OwnerType;
import com.niodata.dp.task.entity.PackageDefaultParams;
import com.niodata.dp.task.entity.PackageOutParams;
import com.niodata.dp.task.entity.PluginSysCategory;
import java.util.Date;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class PluginPackageV2 {

  private String pkgId;
  private int seqId;
  private String pkgVersion;
  private String pkgName;
  private String pkgType;
  private String pkgLang;
  private String jobType;
  private String creator;
  private String pkgPath;
  private String description;
  private PackageParamsV2 params;
  private PackageDefaultParams defaultParams;
  private PackageOutParams outParams;
  private Date createTime;
  private Date updateTime;
  private String developer;
  private String sourceTag;
  private String sourceRepo;
  private boolean publicOn;
  private OwnerType ownerType = OwnerType.GROUP;
  private Long ownerId = new Long(0);
  private PluginSysCategory sysCategory;
  private String funcCategory;
  private String tags = "";
  private PluginPackageV2.PluginStatus status = PluginStatus.Dev;
  private String minPlatformVersion;
  private int taskCount;
  private String scmType = "GitLab";
  private String maintainers;
  private StringList dependencies;
  private String changes;
  private boolean current;
  private boolean failRetry;
  private int downTimes;
  private boolean publicToHub;


  public boolean isUserSetAbleParam(String name) {
    for (PackageParamsV2.PackageParamGroup group : params.getGroups()) {
      for (PackageParamsV2.PackageParamV2 paramV2 : group.relatedParams) {
        if (name.equals(paramV2.name)) {
          return paramV2.userSetAble;
        }
      }
    }
    return false;
  }

  public enum PluginStatus {
    Dev, Deprecated, Release
  }
}

